package org.alino.core.shiro.listener;

import org.alino.core.shiro.session.ShiroSessionRepository;
import org.alino.core.utils.LoggerUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.session.SessionListener;

/**
 * @Desc 会话监听器
 * @Author by Brant
 * @Date 2017/1/13
 */
public class AlinoSessionListener implements SessionListener {
    private ShiroSessionRepository shiroSessionRepository;
    /**
     * 一个回话的生命周期开始
     */
    @Override
    public void onStart(Session session) {
        LoggerUtils.info(getClass(),"=====================session listener on start=====================");
    }
    /**
     * 一个会话的生命周期结束
     */
    @Override
    public void onStop(Session session) {
        LoggerUtils.info(getClass(),"=====================session listener on stop=====================");
    }

    @Override
    public void onExpiration(Session session) {
        shiroSessionRepository.deleteSession(session.getId());
    }

    public ShiroSessionRepository getShiroSessionRepository() {
        return shiroSessionRepository;
    }

    public void setShiroSessionRepository(ShiroSessionRepository shiroSessionRepository) {
        this.shiroSessionRepository = shiroSessionRepository;
    }
}
